#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <pthread.h>

#include "mosquitto.h"
#include "mqtt_client.h"




int main(int argc, char**argv)
{

    const char* host = "localhost";
    const char* port = "1883";
    char * topic = "/mqtt/test";
    const char* username = "admin";
    const char* password = "admin";

    const char* message = " hello mqtt! from rog.mqtt@";

    if (argv[1] != NULL)
        host = argv[1];

    if (argv[2] != NULL)
        message = argv[2];
    
    printf("host=argv[1] message=argv[2] \n");
    printf("is this not set will use default set\n");
    printf("host:%s message:%s\n", host, message);


    if (client_publish_init_connect(host, port, username, password) != 0)
        fprintf(stderr, " mqtt client initial connect and publish failed!\n");
    else
        fprintf(stdout, " mqtt client initial connect and publish successful!\n");


    if (mqtt_client_publish(topic, message) != 0)
        fprintf(stderr, " mqtt client publish to topic:\"%s\" failed!\n", topic);
    else
        fprintf(stdout, " mqtt client publish to topic:\"%s\" successful!\n", topic);

    sleep(2); /* sleep 2s */
    /* client publish and subscribe resource */
    client_publish_release_resource();
}